package lagou.learn.s1m4springboot.controller;

import lagou.learn.s1m4springboot.entity.Article;
import lagou.learn.s1m4springboot.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 黄子濠
 * @date 2020/7/19 16:30
 */
@Controller
public class IndexController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/toIndex")
    public String index(Model model,Integer pageNum){
        if (pageNum==null){
            pageNum=0;
        }
        Page<Article> page = articleService.page(pageNum, 3);
        model.addAttribute("articleList",page.getContent());
        model.addAttribute("currentPage",pageNum);
        model.addAttribute("totalPage",page.getTotalPages()-1);
        return "client/index";
    }
}
